function int2str(num, base) {
    base = base || 10;
    var result = [], n=num, i;
    while(n>0) {
        i = n%base;
        result.push(i);
        n=(n-i)/base
    }
    return result;
}

function isPalindromic(strInteger) {
    var l = strInteger.length;
    var mid = ((l%2==0)?l:l-1)/2;
    for(var i=0; i<mid; i++) {
        if(strInteger[i]!=strInteger[l-i-1]) return false;
    }
    return true;
}

var limit=1000000, sum=0;

for(var i=1; i<limit; i++) {
    if(isPalindromic(int2str(i,10)) && isPalindromic(int2str(i,2))) {
        print(i);
        sum += i;
    }
}

print("Sum=" + sum);
